package com.net.shop.car.manager.ui.personalcenter.oil;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.net.shop.car.manager.R;

public class ProgressDialogUtil {

//	public static ProgressDialog showProgressDialog(Context context,
//			String title, String content, boolean isCancelable) {
//		final ProgressDialog progressDialog = new ProgressDialog(context);
//		progressDialog.setTitle(title);
//		progressDialog.setMessage(content);
//		progressDialog.setCancelable(isCancelable);
//		progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
//
//			@Override
//			public boolean onKey(DialogInterface dialog, int keyCode,
//					KeyEvent event) {
//				if (keyCode == KeyEvent.KEYCODE_BACK) {
//					progressDialog.dismiss();
//				}
//				return false;
//			}
//		});
//		progressDialog.show();
//		return progressDialog;
//	}

	/**
	 * 得到自定义的progressDialog
	 * 
	 * @param context
	 * @param msg
	 * @return
	 */
	public static Dialog showProgressDialog(Context context, String title,
			String content, boolean isCancelable) { 
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
		LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
		ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
		Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
				context, R.anim.loading_animation);
		spaceshipImage.startAnimation(hyperspaceJumpAnimation);
		Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog
		loadingDialog.setCancelable(isCancelable);// 不可以用“返回键”取消
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				480,
				480));// 设置布局
		loadingDialog.show();
		return loadingDialog;

	}

	public static void cancleProgressDialog(Dialog dialog) {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	}
//
//	public static void cancleProgressDialog(ProgressDialog dialog) {
//		if (dialog != null && dialog.isShowing()) {
//			dialog.dismiss();
//		}
//	}
}
